package com.wswy.wyjk.ui.splash;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.text.TextUtils;

import com.blankj.utilcode.util.DeviceUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.PhoneUtils;
import com.blankj.utilcode.util.RomUtils;
import com.kaijia.adsdk.Interface.KjSplashAdListener;
import com.my.httpapi.api.baseUtils.LogUtils;
import com.wswy.wyjk.ui.uitls.SecurityCheckerUtils;

import java.util.HashMap;
import java.util.Map;


public class SplashController {
    private Context context;
    private MyKjSplashAdListener myKjSplashAdListener;

    public SplashController(Context context, MyKjSplashAdListener myKjSplashAdListener) {
        this.context = context;
        this.myKjSplashAdListener = myKjSplashAdListener;
    }

    public Map<String, String> getDeviceInfoMap() {
        Map<String, String> map = new HashMap<>();
        map.put("p", "1");
        map.put("deviceModel", Build.MODEL);  //设备信息
        map.put("deviceManufacture", Build.MANUFACTURER);
        map.put("deviceBrand", Build.BRAND);
        map.put("deviceProduct", Build.PRODUCT);
        map.put("device", Build.DEVICE);
        map.put("deviceFingerprint", Build.FINGERPRINT);
        map.put("androidSDK", String.valueOf(Build.VERSION.SDK_INT));
        map.put("androidId", DeviceUtils.getAndroidID());
        map.put("mac", DeviceUtils.getMacAddress());
        try {
            map.put("deviceId", PhoneUtils.getDeviceId());
        } catch (Exception e) {
        }

        try {
            if (PhoneUtils.getIMEI() != null) {
                map.put("imei", PhoneUtils.getIMEI());
            }
        } catch (Exception e) {
        }

        try {
            if (PhoneUtils.getIMSI() != null) {
                map.put("imsi", PhoneUtils.getIMSI()); //运营商
            }
        } catch (Exception e) {
        }

        try {
            if (PhoneUtils.getMEID() != null) {
                map.put("meid", PhoneUtils.getMEID());
            }
        } catch (Exception e) {
        }

        map.put("hasRoot", String.valueOf(SecurityCheckerUtils.hasRoot(context)));

        map.put("network", SecurityCheckerUtils.getNetWorkType());
        if (TextUtils.equals(map.get("network"), "WIFI")) {
            map.put("wifiIp", NetworkUtils.getIpAddressByWifi());
            map.put("wifiGetway", NetworkUtils.getGatewayByWifi());
            map.put("wifiDhcp", NetworkUtils.getServerAddressByWifi());
            map.put("wifiSSID", SecurityCheckerUtils.getWIFISSID(context));
        }

        try {
            RomUtils.RomInfo romInfo = RomUtils.getRomInfo();
            map.put("rom", romInfo.getName());
            map.put("romVersion", romInfo.getVersion());
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            map.put("appFirstInstallTime", String.valueOf(packageInfo.firstInstallTime));
            map.put("appLastUpdateTime", String.valueOf(packageInfo.lastUpdateTime));
            map.put("pkgName", packageInfo.packageName);
        } catch (Throwable e) {
            e.printStackTrace();
        }

//        for (Map.Entry<String, String> stringStringEntry : map.entrySet()) {
//            Timber.e(stringStringEntry.getKey() + ":" + stringStringEntry.getValue());
//        }
        return map;
    }

    public KjSplashAdListener splashADLinstener = new KjSplashAdListener() {
        @Override
        public void onAdShow() {
            if (myKjSplashAdListener != null) myKjSplashAdListener.onAdShow();
        }

        @Override
        public void onAdDismiss() {
            if (myKjSplashAdListener != null) myKjSplashAdListener.onAdDismiss();
        }

        @Override
        public void onAdClick() {
        }

        @Override
        public void onFailed(String error) {
        }

        @Override
        public void onAdReWard(int i) {
        }
    };

    public interface MyKjSplashAdListener {
        void onAdDismiss();

        void  onAdShow();
    }
}
